package com.api.signature.auto.client.util;

import com.api.signature.auto.client.spring.ApiClientSignContext;
import com.signature.auto.common.util.ApiFoxUtil;
import com.signature.auto.common.util.SecureUtil;
import com.signature.auto.common.util.SignUtil;

import java.util.Map;

/**
 * @author Jerry
 * @date 2024-01-31 17:48
 */
public class ClientSignUtil extends SignUtil {

    /**
     * 字符串加密
     *
     * @param fullStr 待摘要的字符串
     * @return
     */
    @Override
    public String abstractStr(String fullStr) {
        return SecureUtil.md5(fullStr);
    }

    /**
     * 添加参数
     *
     * @param paramsMap 参数列表
     * @param secretKey 密钥
     * @return 公共参数
     */
    @Override
    public Map<String, Object> addSignParams(Map<String, Object> paramsMap, String secretKey) {
        paramsMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
        paramsMap.put("nonce", ApiFoxUtil.getRandomString(32));
        paramsMap.put("appId", ApiClientSignContext.signConfigClient.getAppId());
        paramsMap.put("sign", createSign(paramsMap, secretKey));

        return paramsMap;
    }

    @Override
    public boolean isValidTimestamp(long timestamp) {
        return false;
    }

    @Override
    public boolean isValidParamMap(Map<String, Object> paramMap, String secretKey) {
        return false;
    }

    @Override
    public void checkParamMap(Map<String, Object> paramMap, String secretKey) {
    }
}
